<template>
	<view class='device-list-box'>
		<view class='list' v-if="deviceEntities">
			<view class='item' v-for="(device, index) in deviceEntities" :key="index">
				<view class='top' @click='querySingle(device)'>
					<view class='line'>
						<text
							class="number">{{device.deviceNumber || '--'}}</text><span>|</span>{{device.deviceName || '--'}}
					</view>
					<view class='line'>
						<text class="model">{{device.model || '--'}}</text><span>|</span>{{device.material || '--'}}
					</view>
					<div class='line'>
						{{device.typeName}}
					</div>
					<view class='line status'>
						<view class="line-item">
							<div class='s'>制造状态</div>
							<div class='s'>
								{{device.manufacturingStatus==0?'未开始':(device.manufacturingStatus==1?'执行中':(device.manufacturingStatus==2?'逾期':(device.manufacturingStatus==3?'制造完成':'已发货')))}}
							</div>
						</view>
						<view class="line-item">
							<div class='s'>图纸状态</div>
							<div class='s'>
								{{device.drawStatus==0?'设计中':(device.drawStatus==1?'审核中':(device.drawStatus==2?'已审核':'终版'))}}
							</div>
						</view>
						<view class="line-item">
							<div class='s'>文件状态</div>
							<div class='s'>{{device.documentStatus==0?'编辑中':(device.documentStatus==1?'已审核':'终版')}}
							</div>
						</view>
						<view class="line-item">
							<div class='s'>交工资料</div>
							<div class='s'>
								{{device.handoverStatus==0?'收集中':(device.handoverStatus==1?'编辑中':(device.handoverStatus==2?'审核中':(device.handoverStatus==3?'已批准':(device.handoverStatus==4?'已备案':'已交付'))))}}
							</div>
						</view>
					</view>
				</view>
				<view class='createTime'>
					<view>
						<text class="iconfont icon-rili"></text>创建时间：
						<uni-dateformat :date="device.createTime" format='yyyy-MM-dd hh:mm:ss'></uni-dateformat>
					</view>
					<view>
						<uni-tooltip placement="top">
							<view>更多</view>
							<template slot="content">
								<a @click="deleteSingle(device)">删除</a>&nbsp;/&nbsp;<a
									@click="updateSingle(device)">编辑</a>
							</template>
						</uni-tooltip>
					</view>
				</view>
			</view>
		</view>
		<uni-load-more iconType="circle" v-if="deviceEntities.length" :status="loadingStatus"></uni-load-more>
		<o-empty v-else bg="#f3f3f3"></o-empty>
	</view>
</template>

<script>
	import {
		api,
		post
	} from '@/util/api.js'
	export default {
		props: {
			projectId: ''
		},
		data() {
			return {
				deviceEntities: [],
				count: 0,
				page: 1,
				limit: 10,
				loadingStatus: 'more'
			}
		},
		created() {
			this.queryList()
		},
		methods: {
			async queryList() {
				let device = {
					projectId: this.projectId,
					page: this.page,
					limit: this.limit
				}
				let res = await post(api.DeviceEntities, device)
				this.count = res.count
				this.loadingStatus = "more"
				this.deviceEntities = [...this.deviceEntities, ...res.data]
			},
			querySingle(device) {
				uni.navigateTo({
					url: '/pages/project/device/DeviceInfo?projectId=' + this.projectId + '&deviceId=' + device.id
				})
			},
			deleteSingle(device) {
				let that = this
				uni.showModal({
					title: '提示',
					content: '你确定要删除吗',
					success: function(res) {
						if (res.confirm) {
							post(api.DeleteDevice, {
								id: contract.id
							}).then(res => {
								that.deviceEntities = []
								that.queryList()
							})
						} else if (res.cancel) {
							console.log('取消');
						}
					}
				});
			},
			updateSingle(device) {
				uni.navigateTo({
					url: '/pages/project/device/AddDevice?projectId=' + this.projectId + '&deviceId=' + device.id
				})
			}
		}
	}
</script>

<style lang="scss">
	@import '@/static/css/DeviceList.css';
</style>
